<?php
	$sql="select * from sanpham where 1=1";
	if(isSet($_GET['kind'])){
		$k=$_GET['kind'];
		$sql=$sql." and spStatus=".$_GET['kind'];		
	}
	$res=mysql_query($sql);
	$records=10;
	$totalpage =ceil( mysql_num_rows($res) / $records);
	$page=isSet($_GET['p'])?$_GET['p']:1;
	if(!$page||$page<=0||$page>$totalpage){ 
		$page=1;
	}
	$from=($page-1)*$records;
	$sql=$sql." order by spId DESC limit ".$from.",".$records;
	$res=mysql_query($sql);
?>
<div class="top-bar">
	<a href="main.php?page=apro" class="button">ADD NEW </a>
	<h1>Sản phẩm</h1>
	<div class="breadcrumbs">
		<a href="#">Homepage</a> /
		<a href="#">Sản phẩm</a>
	</div>
</div>
<br />
<div class="select-bar">
	<label>
		<input type="text" name="textfield" />
	</label>
	<label>
		<input type="submit" name="Submit" value="Search" />
	</label>
	&nbsp;
	&nbsp;
	&nbsp;
	&nbsp;
	&nbsp;
	<label>
		<a href="main.php?page=lpro&kind=1">Phần mềm</a>
	</label>	
	&nbsp;
	&nbsp;
	&nbsp;
	<label>
		<a href="main.php?page=lpro&kind=2">Web</a>
	</label>
</div>
<div class="contentWrapper">
<?php
	$res=mysql_query($sql);
	while($r=mysql_fetch_array($res)){
		$ID=$r['spId'];
?>
<div class="perArt">
		<div class='iconPro'>
			<img width='95' height="95" style='margin:auto;' src="<?php echo $r['spImg']; ?>" />
		</div>
		<div class='contentPro'>
		<div class="titleArt"><?php echo substr($r['spTitle'],0,35);?> </div>
		<div class="detailArt"><?php echo substr($r['spDetail'],4,80);?></div>
		<div align="right">
		<a href="#">Chi tiết</a>
		&nbsp;&nbsp;
		<a href="main.php?page=epro&ID=<?php echo $ID; ?>">Sửa</a>
		&nbsp;&nbsp;
		<a href="include/articlesProc.php?type=<?php echo $type;?>&act=del&ID=<?php echo $ID;?>">Xóa</a>
		</div>
		</div>
		<div style="clear:both;"></div>
</div>
<?php
	}
?>
<br>
<br>
<div class="select">
	<strong>Other Pages: </strong>
	<select onChange="location.href='main.php?page=lpro<?php if(isSet($k)) echo "&kind=".$k; ?>&p='+this.value" >
		<?php
			for($i=1;$i<=$totalpage;$i++){
		?>
		<option value="<?php echo $i; ?>" <?php if($i==$page) echo "selected"; ?> ><?php echo $i; ?></option>
		<?php
			}
		?>
	</select>
</div> 
</div>